# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=keepassxc-proxy-static
_projname=keepassxc-proxy-rust
pkgver=0.2.0
pkgrel=1
pkgdesc="A statically linked proxy between Native Messaging browser extension and KeePassXC (for use with Flatpak)"
url="https://github.com/varjolintu/keepassxc-proxy-rust"
# armhf, armv7, riscv64, s390x: fails to build libc crate (SIGSEGV)
arch="all !armhf !armv7 !riscv64 !s390x"
license="GPL-3.0-or-later"
makedepends="cargo cargo-auditable"
install="$pkgname.post-install"
source="https://github.com/varjolintu/keepassxc-proxy-rust/archive/$pkgver/$_projname-$pkgver.tar.gz
	keepassxc-proxy-install.in
	"
builddir="$srcdir/$_projname-$pkgver"

export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"
export RUSTFLAGS="$RUSTFLAGS -C target-feature=+crt-static"

prepare() {
	default_prepare

	sed "s/@@VERSION@@/$pkgver/" "$srcdir"/keepassxc-proxy-install.in \
		> "$srcdir"/keepassxc-proxy-install

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release
}

check() {
	local bin='target/release/keepassxc-proxy'

	if ! file $bin | grep -Fqw 'static-pie linked'; then
		file $bin
		error "$bin is not a static binary!"
		return 1
	fi
}

package() {
	install -D -m755 target/release/keepassxc-proxy "$pkgdir"/usr/libexec/keepassxc-proxy.static
	install -D -m755 "$srcdir"/keepassxc-proxy-install "$pkgdir"/usr/bin/keepassxc-proxy-install
}

sha512sums="
94c4b8ee05ff39d4a96d72198d620fb5ab088cc03cfab81a273fd7aa3b956e55914d1231a03c64d1d80c72d1674391f4c512b1a2273bddf6b94f3891decd6f41  keepassxc-proxy-rust-0.2.0.tar.gz
3d31ed8d2a430f1e61960990128a9b7277106fcf74c16952ccefdeca3a3ba5cb9e6917d08d801bff1d4d354566689bda8f54d10f3711b03063d01374913c0387  keepassxc-proxy-install.in
"
